Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read content-type from response #184

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

read content-type from response #184

wants to merge 1 commit into from

Conversation

leviwheatcroft
Copy link

currently I don't think there's any way to set headers on a per request basis.. this patch allows headers to be set prior to calling nodeStatic.serve.

In addition, currently Content-Type would never be set before being read at line 347, by using res.getHeader you allow this header to be explicitly set on this response outside this module.

@@ -344,7 +344,7 @@ Server.prototype.respondNoGzip = function (pathname, status, contentType, _heade
};

Server.prototype.respond = function (pathname, status, _headers, files, stat, req, res, finish) {
var contentType = _headers['Content-Type'] ||
var contentType = res.getHeader('Content-Type') ||
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we also be checking _headers?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah you're right.. _headers could contain 'Content-Type' if respondGzip or respondNoGzip was called externally. But comparing _headers to res.getHeader here would cause unexpected behavior when someone tries to set headers via whichever method takes lower precedence.

Would it be better to revert line 347 to current master, but ensure internal calls to respond populate the _headers param from res._headers? There's only two at 59, and 78.

Totally understand if you want to kill this PR and look at a cleaner way to add this functionality to the API, I was just playing around with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants